package com.qlk.vorder.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qlk.vorder.domain.SerialLog;
import com.qlk.vorder.domain.query.SerialLogQuery;
import com.qlk.vorder.manager.SerialLogManager;
import com.qlk.vorder.service.SerialLogService;
import com.qlk.vorder.utils.exceptions.ExistedException;
import com.qlk.common.utils.page.PageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.perf4j.aop.Profiled;

/**
 * SerialLogService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-7-28 14:14:00
 * 
 */
@Service
public class SerialLogServiceImpl implements SerialLogService {

	/** LOG */
	private static final Log LOG = LogFactory.getLog(SerialLogServiceImpl.class);

	@Autowired
	private SerialLogManager serialLogManager;

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "SerialLogService.batchInsert")
	public boolean insert(List<SerialLog> serialLogList) {
		boolean resultFlag = false;
		try {
			if (CollectionUtils.isNotEmpty(serialLogList)) {
				resultFlag = serialLogManager.insert(serialLogList);
			} else {
				LOG.warn("SerialLogServiceImpl#batchInsert failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("SerialLogServiceImpl#batchInsert has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "SerialLogService.insert")
	public boolean insert(SerialLog serialLog) {
		boolean resultFlag = false;
		try {
			if (null != serialLog) {
				resultFlag = serialLogManager.insert(serialLog);
			} else {
				LOG.warn("SerialLogServiceImpl#insert failed, param is illegal.");
			}
		} catch (ExistedException e) {
			LOG.warn("SerialLogServiceImpl#insert failed, serialLog has existed.");
			throw e;
		} catch (Exception e) {
			LOG.error("SerialLogServiceImpl#insert has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "SerialLogService.update")
	public boolean update(SerialLog serialLog) {
		boolean resultFlag = false;
		try {
			if (null != serialLog && null != serialLog.getId()) {
				resultFlag = serialLogManager.update(serialLog);
			} else {
				LOG.warn("SerialLogServiceImpl#update failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("SerialLogServiceImpl#update has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "SerialLogService.querySerialLogList")
	public List<SerialLog> querySerialLogList(SerialLogQuery queryBean) {
		List<SerialLog> serialLogList = null;
		try {
			serialLogList = serialLogManager.querySerialLogList(queryBean);
		} catch (Exception e) {
			LOG.error("SerialLogServiceImpl#querySerialLogList has error.", e);
		}
		return serialLogList;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "SerialLogService.querySerialLogListWithPage")
	public List<SerialLog> querySerialLogListWithPage(SerialLogQuery queryBean, PageUtil pageUtil) {
		List<SerialLog> serialLogList = null;
		try {
			serialLogList = serialLogManager.querySerialLogListWithPage(queryBean, pageUtil);
		} catch (Exception e) {
			LOG.error("SerialLogServiceImpl#querySerialLogListWithPage has error.", e);
		}
		return serialLogList;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "SerialLogService.delete")
	public boolean delete(SerialLog serialLog) {
		boolean resultFlag = false;
		try {
			if (null != serialLog && null != serialLog.getId()) {
				resultFlag = serialLogManager.delete(serialLog);
			} else {
				LOG.warn("SerialLogServiceImpl#delete param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("SerialLogServiceImpl#delete has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "SerialLogService.batchDelete")
	public boolean delete(SerialLog[] serialLogs) {
		boolean resultFlag = false;
		try {
			if (null != serialLogs && serialLogs.length > 0) {
				resultFlag = serialLogManager.delete(serialLogs);
			} else {
				LOG.warn("SerialLogServiceImpl#batchDelete failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("SerialLogServiceImpl#batchDelete has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "SerialLogService.getSerialLogById")
	public SerialLog getSerialLogById(Long id) {
		SerialLog serialLog = null;
		try {
			if (null != id) {
				serialLog = serialLogManager.getSerialLogById(id);
			} else {
				LOG.warn("SerialLogServiceImpl#getSerialLogById failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("SerialLogServiceImpl#getSerialLogById has error.", e);
		}
		return serialLog;
	}
}
